﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace BanHangCshap.Class
{
    class Kho : Database
    {
        #region ***** Fields & Properties *****
        private string _makho;
        public string makho
        {
            get
            {
                return _makho;
            }
            set
            {
                _makho = value;
            }
        }
        private string _tenkho;
        public string tenkho
        {
            get
            {
                return _tenkho;
            }
            set
            {
                _tenkho = value;
            }
        }
        private string _diachikho;
        public string diachikho
        {
            get
            {
                return _diachikho;
            }
            set
            {
                _diachikho = value;
            }
        }
        private string _ghichukho;
        public string ghichukho
        {
            get
            {
                return _ghichukho;
            }
            set
            {
                _ghichukho = value;
            }
        }
        #endregion

        #region ***** Init Methods *****
        public Kho()
        {
        }
        public Kho(string makho)
        {
            string sql = "select * from Kho where makho = '" + makho + "'";
            foreach (DataRow dr in getDataTable(sql).Rows)
            {
                this.makho = makho;
                this.tenkho = dr["tenkho"].ToString().Trim();
                this.diachikho = dr["diachikho"].ToString().Trim();
                this.ghichukho = dr["ghichukho"].ToString().Trim();
            }
        }
        public Kho(string makho, string tenkho, string diachikho, string ghichukho)
        {
            this.makho = makho;
            this.tenkho = tenkho;
            this.diachikho = diachikho;
            this.ghichukho = ghichukho;
        }
        #endregion
        public DataTable layDSKho()
        {
            string sql = "select * from Kho";
            return getDataTable(sql);
        }
        public Boolean themKho()
        {
            string sql = "insert into Kho(makho,tenkho,diachikho,ghichukho) values ('" + makho + "',N'" + tenkho + "',N'" + diachikho + "',N'" + ghichukho + "')";
            return executeQuery(sql);
        }
        public Boolean suaKho()
        {
            string sql = "update Kho set tenkho = N'" + tenkho + "',diachikho = N'" + diachikho + "',ghichukho = N'" + ghichukho + "' where makho = '" + makho+ "'";
            return executeQuery(sql);
        }
        public Boolean xoaKho(string makho)
        {
            string sql = "delete Kho where makho = '" + makho + "'";
            return executeQuery(sql);
        }
        public Boolean isExistKho(string makho)
        {
            string sql = "select * from Kho where makho = '" + makho + "'";
            return isExist(sql);
        }
    }
}
